package com.homedo;

import com.google.common.collect.Lists;
import com.homedo.distributed.id.client.gen.IdGen;

import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class IdGenTest3 {
    static AtomicInteger dd = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        List<Thread> tt = Lists.newArrayList();

        for (int i = 0; i < 20; i++) {
            Thread a = new IdThrd("test1");
            a.setDaemon(true);
            a.start();

            tt.add(a);
        }

        for (Thread thread : tt) {
            thread.join();
        }
        System.out.println(dd.get());
    }

    static class IdThrd extends Thread {
        public String bizTag;

        public IdThrd(String bizTag) {
            this.bizTag = bizTag;
        }

        @Override
        public void run() {
//            Set<String> ss = Sets.newHashSet();

            for (int i = 0; i < 100000; i++) {
                if (new Random().nextInt(101) % 10 == 0) {
                    try {
//                        System.out.println("--sleep st-");
                        TimeUnit.SECONDS.sleep(1);
//                        System.out.println("--sleep en-");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                String id = IdGen.regularity(bizTag, 500);
//                System.out.println(id);
//                ss.add(id);
                dd.incrementAndGet();
            }

//            System.out.println(ss.size());
        }
    }
}
